package org.career.pdung.interceptor;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.career.pdung.domain.User;
import org.career.pdung.serviceImpl.UserServiceImpl;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
public class InterceptorSpringMVC implements HandlerInterceptor {
	@Resource(name="userServiceImpl")
	private UserServiceImpl userServiceImpl;
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		return true;
	}
	
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,ModelAndView modelAndView) throws Exception {	
		User currentUser = userServiceImpl.getCurrentUser();
		if(currentUser != null) {
			modelAndView.addObject("currentUser", currentUser.getLastName() + " " + currentUser.getFirstName());
		} 
	}
	
	public void afterCompletion(HttpServletRequest request,HttpServletResponse response, Object handler, Exception ex) throws Exception {
		
	}
}
